// AnsiEditor.h : main header file for the ANSIEDITOR application
//

#if !defined(AFX_ANSIEDITOR_H__C07975C6_FFE8_11D7_B08F_0002553118A0__INCLUDED_)
#define AFX_ANSIEDITOR_H__C07975C6_FFE8_11D7_B08F_0002553118A0__INCLUDED_

#include "MyDispatchDriver.h"	// Added by ClassView
#include "guids.h"
#include "Application.h"	// Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"       // main symbols
#include "MyResource.h"
#include "DocMgrEx.h"
#include "FileDialogEx.h"
#include "MainFrm.h"
#include "AnsiEditorDoc.h"
#include "AnsiEditorView.h"
#include "charbox.h"
#include "DlgReplace.h"	// Added by ClassView
#include "PluginManager.h"	// Added by ClassView
#include "ScriptManager.h"	// Added by ClassView
#include "Options.h"
#include "MUI.h"	// Added by ClassView
#include "MyDocTemplate.h"
#include "AppContext.h"
#include "IntelliChar.h"
#include "StrFuncs.h"

class CAnsiEditorApp;
/////////////////////////////////////////////////////////////////////////////
// CAnsiEditorApp:
// See AnsiEditor.cpp for the implementation of this class
//

//extern CAnsiEditorView *gpView;
extern CMainFrame *gpFrame;
extern CAnsiEditorApp *gpApp;
//extern CAnsiEditorDoc *gpDoc;
extern BOOL gbIsNT5;
//extern CCharBox *gpCharBox;
//extern CAnimateList *gpList;
extern CPluginManager *gpPluginManager;

extern LPCTSTR gszProfileName;
extern CArray<TBBUTTON, TBBUTTON&> garrTbButton;
extern void UpdateCommandMap();

typedef struct tagCommandInfo
{
	int		nCategory;
	int		idCommand;
	int		iBitmap;
	BYTE	fVirt;
	WORD	key;
	//
} CommandInfo;

typedef struct tagCommandInfoEx
{
	int nCommandIndex;
	CString	sAccelerator;
} CommandInfoEx;

#define NOBITMAP -1
#define DO_NOT_IGNORE_CHAR_FLAG (1 << 25)
/* public functions */

void CorrectBadRect(long &x, long& y, long& cx, long&cy);
void CorrectBadRect(int &x, int& y, int& cx, int&cy);

//

extern CString gSeamlessChars;
extern CIntelliChar gIntelliChar;

////
//extern char szCommandCategorys[8][10];
//extern int gnMaxCommandCategory;
extern const int CATEGORY_PLUGIN;
extern CommandInfo gCommands[];
extern int gnCommands;
typedef CMap<UINT, UINT, CommandInfoEx, CommandInfoEx& > CCommandMap;
extern CCommandMap gCommandMap;
extern CString HotKeyToString(BYTE fVirt, WORD key);
extern void SplitString(CString sText, TCHAR cSeparater, CStringArray &rsa);
extern void CDECL ShowError(LPCTSTR szFormat, ...);
extern BOOL WriteTextFile(LPCTSTR szFileName, const CString &sText);
extern BOOL ReadTextFile(LPCTSTR szFileName, CString &sText);
extern CString EncodeXmlText(const CString &text);
extern CString DecodeXmlText(const CString &text);
extern BOOL FileExists(LPCTSTR szFilePath);

extern LPCTSTR gszHorzTransChars;
extern LPCTSTR gszVertTransChars;
//extern BOOL gbIntelTrans;
extern CLIPFORMAT CF_ANSIEDITOR;

class CAppContext;
extern CAppContext* GetAppContext();

template<class T> 
void swap(T& X, T& Y)
{
	T tmp = X;
	X = Y;
	Y = tmp;
}
typedef CArray< int, int > CIntArray;

extern CAppContext gAppContext;
extern CAppContext gAppContext_IP;
extern CAppContext *gpAppContext;
extern HCURSOR ghCursorSizeNS;
extern HCURSOR ghCursorSizeWE;
extern HCURSOR ghCursorSizeALL;

class CAnsiEditorApp : public CWinApp
{
public:
	//
	HANDLE hZ1FontRes;
	//
	BOOL m_bStartedFromRecover;
	CMyDocTemplate* GetDocTemplate();
	CMUI m_mui;
	void UpdateMRUCount();
	COptions m_options;
	CDlgReplace *m_pDlgReplace;
	CScriptManager m_ScriptManager;
	void BeforeApplicationVisible();
	CString& GetAppPath();
	CPluginManager m_PluginManager;
	void LoadPlugins();
	Application m_xApplication;
	void RestoreDefaultIniFile();
	void SetIniFileName(LPCTSTR szName);
	CAnsiEditorApp();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAnsiEditorApp)
	public:
	virtual BOOL InitInstance();
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual int ExitInstance();
	virtual BOOL OnIdle(LONG lCount);
	//}}AFX_VIRTUAL

// Implementation
	COleTemplateServer m_server;
		// Server object for document creation
	//{{AFX_MSG(CAnsiEditorApp)
	afx_msg void OnAppAbout();
	afx_msg void OnOptions();
	afx_msg void OnViewGrid();
	afx_msg void OnUpdateViewGrid(CCmdUI* pCmdUI);
	afx_msg void OnEditReplace();
	afx_msg void OnAccelerators();
	afx_msg void OnUpdateVerticalInput(CCmdUI* pCmdUI);
	afx_msg void OnVerticalInput();
	afx_msg BOOL OnOpenRecentFile(UINT nID);
	//}}AFX_MSG
	afx_msg void OnUpdateViewCanvasMode(CCmdUI* pCmdUI);
	afx_msg void OnUpdateViewDisplayMode(CCmdUI* pCmdUI);
	afx_msg void OnViewCanvasMode(UINT nID);
	DECLARE_MESSAGE_MAP()
protected:
	void InitTbButton();
	void CacheAppPath();
	CString m_sAppPath;
};


/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_ANSIEDITOR_H__C07975C6_FFE8_11D7_B08F_0002553118A0__INCLUDED_)
